/**
 * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package org.opsli.modulars.shop.userorder.service.impl;
import org.opsli.common.utils.WrapperUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.opsli.core.base.service.impl.CrudServiceImpl;

import org.opsli.modulars.shop.userorder.entity.SysUserOrder;
import org.opsli.api.wrapper.shop.userorder.SysUserOrderModel;
import org.opsli.modulars.shop.userorder.service.ISysUserOrderService;
import org.opsli.modulars.shop.userorder.mapper.SysUserOrderMapper;


/**
 * 用户订单 Service Impl
 *
 * @author 17607080935
 * @date 2025-01-08 15:52:29
 */
@Service
public class SysUserOrderServiceImpl extends CrudServiceImpl<SysUserOrderMapper, SysUserOrder, SysUserOrderModel>
    implements ISysUserOrderService {

    @Autowired(required = false)
    private SysUserOrderMapper mapper;

    /**
     * 订单预约成功
     * @param orderId
     * @return
     */
    @Override
    public SysUserOrderModel orderSuccess(String orderId) {
        SysUserOrder order= mapper.selectById(orderId);
        if (order != null&&"0".equals(order.getStatus())){
            order.setStatus("1");
        }
        mapper.updateById(order);
        return WrapperUtil.transformInstance(order, SysUserOrderModel.class);
    }

    /**
     * 支付成功
     * @param orderId
     * @return
     */
    @Override
    public void paySuccess(String orderId) {
        SysUserOrder order= mapper.selectById(orderId);
        //判断是否已经支付
        if (order != null&&"0".equals(order.getStatus())){
            order.setPriceStatus("1");
            mapper.updateById(order);
            orderSuccess(orderId);
        }

    }
}